Skip to content

Refactor/barcode1d typed locale#31

Merged
u8array merged 4 commits into
mainfrom
refactor/barcode1d-typed-locale
May 8, 2026
Merged

Refactor/barcode1d typed locale#31
u8array merged 4 commits into
mainfrom
refactor/barcode1d-typed-locale

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 8, 2026

No description provided.

u8array added 4 commits May 8, 2026 23:27
The PropertiesPanel cast (t.registry as unknown as Record<string,
BarcodeLocale>)[config.localeKey] stripped type safety from every 1D
barcode registry: a typo or renamed key compiled cleanly and showed
empty labels at runtime.

Replace localeKey: string with locale: (t) => BarcodeLocale at the
config level. Each registry call site picks its block as
'(t) => t.registry.<key>', which TS verifies both for existence and
for shape against the BarcodeLocale interface. Drop the cast in the
panel; loc is now plainly BarcodeLocale.

14 1D barcode registries migrated (code128 / code39 / ean13 keep
their inline panels and aren't affected).
Previously barcode1d.tsx derived the translation type via
ReturnType<typeof useT>, coupling a pure data type to a React hook.
The hook is one consumer of the type, not its source.

Move the type to locales/index.ts where the locale data lives. useT
now consumes Translations rather than producing it; non-React modules
(future SSR, tests, lib code) can pick up the type without pulling
the React-bound hook.
These three were the last 1D barcodes carrying their own inline
PropertiesPanel and toZPL — virtually identical to what createBarcode1D
emits. The duplication was an old smell waiting on type-safe locale
handling (which the previous commit landed).

- code128 / code39: direct migration with hasCheckDigit: true. code39
  keeps its content-spec (charset filter) via the helper's contentSpec
  parameter.
- ean13: adopts Barcode1DProps (gains an unused checkDigit: boolean).
  hasCheckDigit: false hides the checkbox in the panel; toZPL ignores
  the field. zplParser and testModels updated to set checkDigit: false
  explicitly. The data-shape change is forward-only — runtime never
  reads p.checkDigit on EAN-13.

Net: ~240 lines of duplicated panel/toZPL code deleted.
Make the type contract explicit at the hook boundary. Inferred return
already equals Translations, but the annotation locks the shape and
fails fast if locales[code] ever drifts.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the 1D barcode registry by introducing a createBarcode1D helper to reduce boilerplate and replacing string-based localeKey references with a type-safe locale selector function. It also updates EAN-13 barcode properties to include a default checkDigit value. I have no feedback to provide.

@u8array u8array merged commit 2a6daae into main May 8, 2026
2 checks passed
@u8array u8array deleted the refactor/barcode1d-typed-locale branch May 9, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant